﻿using UnityEngine.Profiling;
using UnityEngine;

namespace SoarD.Pandora.Console
{
    public partial class PdrConsoleWindow
    {
        private sealed class ProfilerInfoWindow : ScrollWindowBase
        {
            private const float KBSize = 1024;
            private const float MBSize = 1024 * KBSize;

            protected override void OnDrawScrollableWindow()
            {
                GUILayout.Label("<b>Unity Profiler</b>");
                GUILayout.BeginVertical("box");
                {
                    DrawItem("Mono自身内存:", string.Format("{0} MB", (Profiler.GetMonoUsedSize() / MBSize).ToString("F3")));
                    DrawItem("Mono使用内存:", string.Format("{0} MB", (Profiler.GetMonoHeapSize() / MBSize).ToString("F3")));
                    DrawItem("堆内存使用:", string.Format("{0} MB", (Profiler.usedHeapSize / MBSize).ToString("F3")));
                    DrawItem("总内存分配:", string.Format("{0} MB", (Profiler.GetTotalAllocatedMemory() / MBSize).ToString("F3")));
                    DrawItem("总预留内存:", string.Format("{0} MB", (Profiler.GetTotalReservedMemory() / MBSize).ToString("F3")));
                    DrawItem("未使用内存:", string.Format("{0} MB", (Profiler.GetTotalUnusedReservedMemory() / MBSize).ToString("F3")));
                    DrawItem("临时内存:", string.Format("{0} MB", (Profiler.GetTempAllocatorSize() / MBSize).ToString("F3")));
                }
                GUILayout.EndVertical();
                if (!ShowLuaMemory) return;
                GUILayout.Label("<b>Lua Profiler</b>");
                GUILayout.BeginVertical("box");
                {
                    DrawItem("Lua内存:", string.Format("{0} MB", (luaMemorySize / KBSize).ToString("F3")));
                    DrawItem("Lua内存(单位秒):", string.Format("{0} KB", luaMemoryDelta));
                }
                GUILayout.EndVertical();
            }
        }
    }
}
